﻿@{
	Layout = null;
}
<link href="~/libs/layui-v2.9.21/layui-v2.9.21/layui/css/layui.css" rel="stylesheet" />

<div class="layui-form-item">
	<div class="layui-input-block">
		<button type="button" class="layui-btn"  lay-on="addUser">
			新增
		</button>
	</div>
</div>

<table class="layui-hide" id="table1" lay-filter="test"></table>

<script type="text/html" id="operateBtn">
	<button class="layui-btn layui-btn-xs  layui-bg-radius" style=background-color:blue lay-event="update" >修改</button>
	<button class="layui-btn layui-btn-xs  layui-bg-radius" style=background-color:red lay-event="delete" >删除</button>
	<button class="layui-btn layui-btn-sm  layui-bg-radius" style=background-color:info lay-event="assigningRoles" >分配角色</button>
</script>
<script src="~/libs/jquery/jquery.js"></script>
<script src="~/libs/layui-v2.9.21/layui-v2.9.21/layui/layui.js"></script>
<script>
	layui.use(['table'],function (){
		var table =layui.table

		queryList=function (){
			table.render({
				elem:'#table1',
				url:'/RBAC/GetUserList',
				// type:'get',
				// dataType:'json',
				page:true,
				limit:10,
				limits:[10,20,30],
				cols:[[
						 { field: 'id', title: '用户编号'  },
						 { field: 'userName', title: '用户名'  },
						 { field: 'userPass', title: '密码' },
						 { field: 'userNickname', title: '昵称'  },
						 { field: 'userPhone', title: '联系方式' },
						 { field: 'userStatus', title: '状态',
							 templet:function (row){
								 var tempStatus=row.userStatus==1?"启用":"禁用"
								 return tempStatus
							 }
						 },
						  { title: '操作',toolbar:'#operateBtn',width:280 },
				]],
				success:function (res){
					console.log(res)
				}
			})
		}

		queryList();


		  table.on('tool(test)',function(obj){
				layEvent = obj.event;
				data = obj.data;
				if (layEvent === 'delete') {
				layer.confirm('确定删除吗？', function (index) {
					$.ajax({
						url: "/RBAC/DeleteUser",
						data: {
							id: data.id,
						},
						type: "post",
						datatype: "json",
						success: function (res) {
							console.log(res)
							if (res>0) {
								layer.msg('删除成功');
								queryList();
							} else {
								layer.msg('删除失败: ' + res.msg);
							}
						}
					 })
				layer.close(index); //关闭弹框
				})
			}else{
				 layer.open({
					 type:2,
					 title:'编辑',
					area: ['650px', '500px'],
					 shade: 0.6, // 遮罩透明度
					 shadeClose: true, // 点击遮罩区域，关闭弹层
					 maxmin: true, // 允许全屏最小化
					 anim: 0, // 0-6 的动画形式，-1 不开启
					 content:['/RBAC/UpdateUserView?id='+data.id, 'no'],
					 end:function (){
						 location.reload();
					 }
				 })
			}

			// /UserRole/AddUserRolesView
		})
	})


			//新增弹框
	layui.use(function(){
	  var $ = layui.$;
	  var layer = layui.layer;
	  var util = layui.util;
	  // 事件
	  util.on('lay-on', {
		'addUser': function(){
		  layer.open({
			type: 2,
			area: ['650px', '500px'],
			title:'添加用户',
			skin: 'layui-layer-rim', // 加上边框
			content: ['/RBAC/AddUserView', 'no'] // 数组第二个成员设为 no 即屏蔽 iframe 滚动条
		  });
		},
	  })
	});


</script>